package br.com.agregador.servicoimpl;

import java.io.UnsupportedEncodingException;
import java.util.Date;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import br.com.agregador.servico.EmailService;

@Service(value="emailService")
public class EmailServiceImpl implements EmailService {
	
	private static final long serialVersionUID = 1L;
	@Autowired
	private JavaMailSenderImpl javaMailSenderImpl;
	
	@Override
	public void enviarSenha(String emailPara, String senha) throws MessagingException {
		MimeMessage message = javaMailSenderImpl.createMimeMessage();
		MimeMessageHelper msg = new MimeMessageHelper(message,true);	
		msg.setTo(emailPara);
		msg.setSubject("xxxxxx");
		msg.setSentDate(new Date());		
		try {
			msg.setFrom("xxxxxxx@gmail.com","AGREGADOR");
		} catch (UnsupportedEncodingException e) {			
		}
		msg.setText("html",true);       
		javaMailSenderImpl.send(message);
	}

}
